package com.demo.utils;

import javax.servlet.http.Cookie;

public class CookieUtils {

    /**
     * 查找指定名称的Cookie
     *
     * @param name
     * @param cookies
     * @return
     */
    public static Cookie findCookie(String name, Cookie[] cookies) {
        if (name == null || cookies == null) {
            return null;
        }
        for (Cookie cookie :
                cookies) {
            if (name.equals(cookie.getName())) {
                return cookie;
            }
        }
        return null;
    }

    public static void deleteCookie(Cookie cookie) {
        cookie.setMaxAge(0);
    }
}
